<section class="header clearfix">
  <h1>
    {{header}}
  </h1>
</section>

<div class="row">
  <div class="col span-11-of-23 mt-0 mb-0">
    {{form-name-description
      name=name
      nameDisabled=isUpgrade
      nameRequired=(not isUpgrade)
      bothColClass="col span-12 mt-0"
      colClass="col span-12 mt-0"
      description=description
      descriptionShown=false
      namePlaceholder="newContainer.name.placeholder"
      descriptionPlaceholder="newContainer.description.placeholder"
    }}
  </div>
  <div class="col span-11-of-23 mt-0 mb-0 offset-1-of-23">
    {{#if isSidekick}}
      <label class="acc-label">
        {{t "newContainer.containerType.title"}}
      </label>
      <div class="radio">
        <label>
          {{radio-button
            selection=launchConfig.initContainer
            value=false
          }} {{t "newContainer.containerType.standard"}}
        </label>
      </div>
      <div class="radio">
        <label>
          {{radio-button
            selection=launchConfig.initContainer
            value=true
          }} {{t "newContainer.containerType.init"}}
        </label>
      </div>
    {{else}}
      {{container/form-scale
        initialScale=scale
        isGlobal=isGlobal
        launchConfigIndex=launchConfigIndex
        workload=service
        isUpgrade=isUpgrade
        errors=scaleErrors
        scaleMode=scaleMode
        setScale=(action (mut scale))
      }}
    {{/if}}
  </div>
</div>

<hr class="mt-30 mb-30" />

<div class="row">
  <div class="col span-{{if showTargetOS "9" "11"}}-of-23 mt-0 mb-0">
    {{container/form-image
      initialValue=launchConfig.image
      errors=imageErrors
      changed=(action "setImage")
    }}
  </div>

 {{#if showTargetOS}}
   <div class="col span-5-of-23 mt-0 mb-0">
    <label class="acc-label pb-5">
      {{t "newContainer.os"}}
      {{field-required}}
    </label>
    <div class="row">
      <div class="btn-group no-inline-space mt-5">
        <button
          class="btn btn-link btn-sm bg-{{if (eq targetOs "all") "primary" "default" }}" type="button" {{action "setTargetOs" "all"}}
        >
          {{t "newContainer.all"}}
        </button>
        <button
          class="btn btn-link btn-sm bg-{{if (eq targetOs "linux") "primary" "default" }}" type="button" {{action "setTargetOs" "linux"}}
        >
          <i class="icon icon-fw icon-linux"></i>
          {{t "newContainer.linux"}}
        </button>
        <button
          class="btn btn-link btn-sm bg-{{if (eq targetOs "windows") "primary" "default" }}" type="button" {{action "setTargetOs" "windows"}}
        >
          <i class="icon icon-fw icon-windows"></i>
          {{t "newContainer.windows"}}
        </button>
      </div>
    </div>
    </div>
  {{/if}}
  {{#unless isSidekick}}
    <div class="col span-{{if showTargetOS "8" "11"}}-of-23 mt-0 mb-0 offset-1-of-23">
      {{form-namespace
        namespace=namespace
        errors=namespaceErrors
        editing=(not (or isUpgrade isSidekick))
        registerHook=(action "registerHook")
      }}
    </div>
  {{/unless}}
</div>

<hr class="mt-30 mb-30" />
<div class="row">
  {{container/form-ports
    initialPorts=launchConfig.ports
    showWarning=(and isUpgrade (not service.isCreatedByRancher))
    changed=(action (mut launchConfig.ports))
    errors=portErrors
    editing=true
  }}
</div>

<hr class="mt-30 mb-30" />
{{#accordion-list as | al expandFn | }}
  {{#if (or (eq scaleMode "job") (eq scaleMode "cronJob"))}}
    {{container/form-job-config
      workload=service
      scaleMode=scaleMode
      editing=true
      expandAll=al.expandAll
      expandFn=expandFn
    }}
  {{/if}}

  {{#accordion-list-item
     title=(t "newContainer.environment.label")
     detail=(t "newContainer.environment.detail" appName=settings.appName)
     status=status
     statusClass=statusClass
     expandAll=al.expandAll
     expand=(action expandFn)
  }}
    {{form-key-value
      initialMap=launchConfig.environment
      changed=(action (mut launchConfig.environment))
      allowEmptyValue=true
      editing=true
      header=(t "newContainer.environment.label")
      addActionLabel="newContainer.environment.addAction"
      keyLabel="newContainer.environment.keyLabel"
      keyPlaceholder="newContainer.environment.keyPlaceholder"
      valueLabel="newContainer.environment.valueLabel"
      valuePlaceholder="newContainer.environment.valuePlaceholder"
    }}
    <hr class="mt-30 mb-30" />
    {{container/form-sources
      namespace=namespace
      classNames="accordion-wrapper"
      sources=launchConfig.environmentFrom
      errors=secretErrors
      editing=true
    }}

  {{/accordion-list-item}}

  {{#unless isSidekick}}
    {{container/form-scheduling
      isGlobal=isGlobal
      initialHostId=service.scheduling.node.nodeId
      service=service
      scheduling=service.scheduling
      errors=schedulingErrors
      editing=true
      expandAll=null
      setRequestedHost=(action "setRequestedHostId")
      expandAll=al.expandAll
      expandFn=expandFn
    }}
  {{/unless}}

  {{#accordion-list-item
     title=(t "formHealthCheck.title")
     detail=(t "formHealthCheck.detail" appName=settings.appName)
     status=status
     statusClass=statusClass
     expandAll=al.expandAll
     expand=(action expandFn)
  }}
    <div class="row">
      <div class="col span-6 mt-0 mb-0">
        <label class="acc-label">
          {{t "formHealthCheck.readiness"}}
        </label>
      </div>
      <div class="col span-6 mt-0 mb-0">
        {{#if separateLivenessCheck}}
          <label class="acc-label">
            {{t "formHealthCheck.liveness"}}
          </label>
          <div class="pull-right text-small">
            <button class="btn bg-transparent p-0" type="button" {{action "toggleSeparateLivenessCheck"}}>{{t "formHealthCheck.combinedLivenessCheck"}}</button>
          </div>
        {{else}}
          <div class="pull-right text-small">
            <button class="btn bg-transparent p-0" type="button" {{action "toggleSeparateLivenessCheck"}}>{{t "formHealthCheck.separateLivenessCheck"}}</button>
          </div>
        {{/if}}
      </div>
    </div>
    <div class="row">
      <div class="col {{if separateLivenessCheck "span-6" "span-12"}}">
        {{form-healthcheck
          initialCheck=launchConfig.readinessProbe
          changed=(action (mut launchConfig.readinessProbe))
          errors=readyCheckErrors
          editing=true
        }}
      </div>
      {{#if separateLivenessCheck}}
        <div class="col span-6">
          {{form-healthcheck
            initialCheck=launchConfig.livenessProbe
            changed=(action (mut launchConfig.livenessProbe))
            errors=liveCheckErrors
            editing=true
            successMustBeOne=true
            isLiveness=true
          }}
        </div>
      {{/if}}
    </div>
  {{/accordion-list-item}}

  {{container/form-volumes
    errors=volumeErrors
    expandAll=al.expandAll
    expandFn=expandFn
    launchConfig=launchConfig
    loggingEnabled=loggingEnabled
    namespace=namespace
    registerHook=(action "registerHook")
    workload=service
    scaleMode=scaleMode
  }}

  {{#unless isSidekick}}
    {{container/form-upgrade
      workload=service
      scaleMode=scaleMode
      editing=true
      isUpgrade=isUpgrade
      expandAll=al.expandAll
      expandFn=expandFn
    }}
  {{/unless}}

  {{#advanced-section advanced=advanced}}
    {{container/form-command
      classNames="accordion-wrapper"
      instance=launchConfig
      scaleMode=scaleMode
      errors=commandErrors
      service=service
      isSidekick=isSidekick
      expandAll=al.expandAll
      expandFn=expandFn
    }}

    {{#unless isSidekick}}
      {{container/form-networking
        classNames="accordion-wrapper"
        instance=launchConfig
        errors=networkingErrors
        service=service
        editing=true
        expandAll=al.expandAll
        expandFn=expandFn
      }}

      {{form-labels-annotations
        classNames="accordion-wrapper"
        labelErrors=labelErrors
        initialLabels=service.labels
        expandAll=al.expandAll
        expandFn=expandFn
        model=service
        annotationErrors=annotationErrors
      }}
    {{/unless}}

    {{container/form-security
      instance=launchConfig
      service=service
      errors=securityErrors
      isSidekick=isSidekick
      editing=true
      expandAll=al.expandAll
      expandFn=expandFn
      expanded=securitySectionExpanded
    }}

    {{#unless isSidekick}}
      {{#if (or (and scope.currentProject.isSystemProject scope.currentCluster.enableClusterMonitoring) scope.currentProject.enableProjectMonitoring)}}
        {{container/form-custom-metrics
          classNames="accordion-wrapper"
          workload=service
          editing=true
          expandAll=al.expandAll
          expandFn=expandFn
        }}
      {{/if}}
    {{/unless}}
  {{/advanced-section}}
{{/accordion-list}}

{{top-errors errors=errors}}
{{save-cancel
  createLabel=(if isUpgrade "newContainer.saveUpgrade" "newContainer.saveNew")
  save=(action "save")
  cancel=(action "cancel")
}}
